1 import tkinter
2 import threading
3 from tkinter import messagebox
4 import sys
5
6 tasks = []
7 timer = threading
8 real_timer = threading
9 ok_thread = True
10
11
12 def get_entry(event=""):
13 text = todo.get()
14 hour = int(time.get())
15 todo.delete(0, tkinter.END)
16 time.delete(0, tkinter.END)
17 todo.focus_set()
18 add_list(text, hour)
19 if 0 < hour < 999:
20 update_list()
21
22
23 def add_list(text, hour):
24 tasks.append([text, hour])
25 timer = threading.Timer(hour, time_passed, [text])
26 timer.start()
27
28
29 def update_list():
30 if todolist.size() > 0:
31 todolist.delete(0, "end")
32 for task in tasks:
33 todolist.insert("end", "[" + task[0] + "] Time left: " + str(task[1]) + " secondes")
34
35
36 def time_passed(task):
37 tkinter.messagebox.showinfo("Notification", "Time for : " + task)
38
39
40 def real_time():
41 if ok_thread:
42 real_timer = threading.Timer(1.0, real_time)
43 real_timer.start()
44 for task in tasks:
45 if task[1] == 0:
46 tasks.remove(task)
47 task[1] -= 1
48 update_list()
49
50
51 if __name__ == '__main__':
52 # application
53 app = tkinter.Tk()
54 app.geometry("480x680")
55 app.title("Todolist Remainder")
56 app.rowconfigure(0, weight=1)
57
58 # fenetre
59 frame = tkinter.Frame(app)
60 frame.pack()
61
62 # widgets
63 label = tkinter.Label(app, text="Enter work to do:",
64 wraplength = 200,
65 justify = tkinter.LEFT)
66 label_hour = tkinter.Label(app, text="Enter time (secondes)",
67 wraplength = 200,
68 justify = tkinter.LEFT)
69 todo = tkinter.Entry(app, width=30)
70 time = tkinter.Entry(app, width=15)
71 send = tkinter.Button(app, text='Add task', fg="#ffffff", bg='#6186AC', height=3, width=30, command=get_entry)
72 quit = tkinter.Button(app, text='Exit', fg="#ffffff", bg='#EB6464', height=3, width=30, command=app.destroy)
73 todolist = tkinter.Listbox(app)
74 if tasks != "":
75 real_time()
76
77 # binding
78 app.bind('<Return>', get_entry)
79
80 # widgets placement
81 label.place(x=0, y=10, width=200, height=25)
82 label_hour.place(x=235, y=10, width=200, height=25)
83 todo.place(x=62, y=30, width=200, height=25)
84 time.place(x=275, y=30, width=50, height=25)
85 send.place(x=62, y=60, width=50, height=25)
86 quit.place(x=302, y=60, width=50, height=25)
87 todolist.place(x=60, y = 100, width=300, height=300)
88
89 app.mainloop()
90 ok_thread = False
91 sys.exit("FINISHED")